<?php
/*
 * Webing - The SNS Blog
 *
 * Copyright (c) 2009 Webing. All rights reserved.
 *
 * This is webing error class 
 */
/*$Id: webing_error.php 59 2009-08-10 10:20:43Z chopins.xiao $;*/

final class webing_error
{
    static private $error_tracker = array();
    static private $file_tracker = array();
    private $php_error;
    /**
     * Construct webing error
     *
     * @param array $msg
     */
    public function __construct(array $msg)
    {
        if(isset($msg['PHP_TRACKER']))
        {
            $this->tracker($msg);
            return;
        }else{
            $this->error($msg);
            return;
        }
    }
    private function display()
    {
        echo '<html><head><title>Webing Error Tracker</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" ></head><body>';
        if(isset($this->php_error['FILE'], $this->php_error['TRACKER']))
        {
            $this->file_tracker[] = $this->php_error['FILE'];
            $this->error_tracker[] = $this->php_error['TRACKER'];
            unset($this->php_error['FILE'], $this->php_error['TRACKER']);
        }
        foreach ($this->file_tracker as $key => $var)
        {
            echo "<b>$var</b><br />";
            foreach ($this->error_tracker[$key] as $line => $tag)
            {
                echo "&nbsp;&nbsp;&nbsp;&nbsp;Line: $line  Tag: $tag <br />";
            }
        }
        foreach ($this->php_error as $index => $value)
        {
            echo "<b>$index</b>:$value<br />";
        }
        echo '</body></html>';
        if($this->php_error['LEVEL'] == 1)
        {
            exit();
        }
    }
    public function error($errno, $error, $file, $line)
    {
        $err_buff = unserialize($error);
        if(is_array($err_buff))
        {
            $err_array = $err_buff;
        }else{
            $err_array = array();
            $err_array['PHP_ERROR'] = $error;
        }
        $this->php_error['PHP_FILE'] = $file;
        $this->php_error['PHP_LINE'] = $line;
        $this->php_error['PHP_ERROR_NO'] = $errno;
        $this->display();
    }
    public function tracker($tracker)
    {
        $this->file_tracker[] = $tracker['FILE'];
        $this->error_tracker[][$tracker['LINE']] = $tracker['PHP_TRACKER'];
    }
}

